﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MO.ModelingClient
{
    public partial class ListForm : Form
    {
        public ListForm()
        {
            InitializeComponent();
        }

        private void ListForm_Shown(object sender, EventArgs e)
        {
            DataConfig config = new DataConfig();
            config.TableName = "List_Define";
            config.KeyField = "LD_Code";
            config.TitleField = "LD_Name";
            config.AddItem(new ItemData("LD_Code", "编码"));
            config.AddItem(new ItemData("LD_Name", "名称"),true);
            config.AddItem(new ItemData("LD_Query_Sql", "SQL查询语句")
            {
                GetBaseTextEditForm = delegate()
                {
                    List<TreeNode> list = new List<TreeNode>();
                    var entitys = DataManager.FindAllEntity();
                    foreach (var ent in entitys)
                    {
                        TreeNode entityNode = new TreeNode(ent.Name) { Tag = ent.Code };
                        list.Add(entityNode);
                        foreach (var field in DataManager.FindFieldByEntityCode(ent.Code))
                        {
                            entityNode.Nodes.Add(field.Name).Tag = field.Code;
                        }
                    }
                    list.Add(new TreeNode("当前用户编码") { Tag = "[UserCode]" });
                    return new ScriptEditForm(list.ToArray());
                }
            });
            config.AddItem(new ItemData("LD_Query_Script", "查询脚本"));
            config.AddItem(new ItemData("LD_View_Template", "界面模版"));
            tableControl1.Init(config);
        }
    }
}
